<!-- 售后 -->
<template>
    <div class="page-box h100 display-flex czbj">
      <p class="title-label mb10">售后</p>
      <dxtable
        :dataJson="dataJson"
        :portUrl="portUrl"
        :formJson="formJson"
        :qx="qx"
        :czFun="czFun"
        ref="databale"
           :fixed="true"
      ></dxtable>
  
      <n-modal v-model:show="showModal" preset="card" class="dfdsrtyrytyt">
        <template #header>
          <div>同意退款</div>
        </template>
        <div>
            <p>退款金额</p>
            <n-input v-model:value="tukjs" type="text" placeholder="请输入退款金额" class="mt10" />
          <p class="z9 mt10 fz12">
            该笔支付方式为{{ kdfdsf(rowData.zhifuqd) }} 将原路返回
          </p>
          </div>
        <template #action>
          <div class="tr">
            <n-button type="info" @click="kdsfsdytty"> 确认 </n-button>
            <n-button class="ml20" @click="showModal = false"> 关闭 </n-button>
          </div>
        </template>
      </n-modal>
    </div>
  </template>
  <script lang="ts" setup>
  import { Options } from "@vicons/ionicons5";
  import dxtable from "../../../components/util/dxtable.vue";
  import sort from "../../../components/util/sort.vue";
  import { dxget, dxpost, dialog } from "../../../util/index";
  import { NButton, NImage, NTag } from "naive-ui";
  import { h, ref, reactive, render } from "vue";
  const databale = ref();
  const showModal = ref(false);
  const rowData = ref({});
  const shhehsdrt = ref();
  const hjshsd = ref();
  const kjxzdd = ref([]);
  const ShipperCode = ref();
  const LogisticCode = ref();
  const Traces =ref([])
  const jdasfsd =ref(false)
  const Reason =ref()
  const tukjs  =ref(0)
  const initeer = () => {
    databale.value.initDataExpose();
  };
  const shjjseft = ref("1");
  let zhidfds = [
  {
    label: "微信",
    value: "1",
  },
  {
    label: "支付宝",
    value: "2",
  },
  {
    label: "平台币",
    value: "3",
  },
];
  let dataJson = [
    {
      title: "订单编号",
      key: "ddON",
      width: "180",
    },
    {
      title: "快递公司",
      key: "ktgs",
      options: [],
      render(row) {
        try{
            return kjxzdd.value.filter((a) => a.value == row.ktgs)[0].label;
        }catch(e){
            return '--'
        }
      },
    },
    {
      title: "快递编码",
      key: "ktbh",
    },
    {
      title: "商品名称",
    key: "c.title",
    search: true,
    render(row) {
      return row.jstitle;
    },
    },
    {
      title: "单价",
      key: "jsdanjia",
    },
    {
      title: "数量",
      key: "number",
    },{
      title: "支付金额",
      key: "jiner",
    },
    {
      title: "支付方式",
    key: "zhifuqd",
    type: "select",
    options: [
      {
        label: "全部",
        value: "",
      },
      ...zhidfds,
    ],
    search: true,
    width: 80,
      render(row) {
        let ksdfsd = "--"
        if(row.zhifuqd==1){
          ksdfsd="微信"
        }
        if(row.zhifuqd==2){
           ksdfsd="支付宝"
        }
        if(row.zhifuqd==3){
          ksdfsd="平台币"
        }
        return ksdfsd
      }
    },
    {
      title: "购买人姓名",
    width: 80,
    key: "b.name",
    search: true,
    render(row) {
      return row.uname;
    },
    },
    {
      title: "电话",
      key: "uphone",
    },
  
    {
      title: "下单时间",
      key: "addTime",
      width: 150,
    },
    {
      title: "发货时间",
      key: "fhsj",
      width: 150,
    },
  
  
    
  ];
  
  const qx = {
    DeletePermissionID: "23456", //删除
    EditPermissionIdentifier: "23456", // 编辑
    NewPermissionIdentifier: "234567", // 新建
    ViewPermissionID: "234567", // 查看
  };
  const portUrl = "jyc/dingdanzhuangtai/dingdanzhuangtai?type=2&state=5";
  
  let formJson = reactive([]);
  // 获取字典内容
  const xtgxxmfl = async () => {
    const { data }: any = await dxget("dxgjAdmin/getzd", { name: "jyckdgsbm" });
    kjxzdd.value = data;
  };
  xtgxxmfl();
  const shenhedtyt = async () => {
   
  };
  const kdfdsf =(data)=>{
    return zhidfds.filter(a=>a.value==data)[0].label
  }
  const czFun = {
    fun: (row) => {
      return [
        h(
          NButton,
          {
            type: "info",
            quaternary: true,
            onClick: async (e) => {
                let statics: any = await dialog("是否取消退款？");
                if (statics == 1) {
                    let jsdfsdf =2
                    if(row.ktbh){
                        jsdfsdf=3
                    }
                    await dxpost("jyc/dingdanzhuangtai/dingdanzhuangtai",{id:row.id,state:jsdfsdf},"put")
                    initeer()
                }
            },
          },
          "取消退款"
        ),
        h(
          NButton,
          {
            type: "info",
            quaternary: true,
            onClick: async (e) => {
                showModal.value = true
                tukjs.value = row.jiner
                rowData.value = row
            },
          },
          "同意退款"
        ),
      ];
    },
  };
  const kdsfsdytty = async(data)=>{

    if(rowData.value.zhifuqd==1){//微信退款
    const jdfsdfs =  await dxpost("jyc/wxzhifu/index/refund",{
        out_refund_no:rowData.value.out_trade_no,
        total:rowData.value.jiner
      })
      if(jdfsdfs.data.status!=200){
        window.$message.error(jdfsdfs.data.data)
      }
    }
    await dxpost("jyc/dingdanzhuangtai/dingdanzhuangtai",{id:rowData.value.id,state:6},"put")

    // 平台币退款
    if(data.zhifuqd==3){
    await dxpost("jyc/jycadmin/ptjiansdd",{
        id:rowData.value.uid,
        leixing:1,
        jiner:tukjs.value,
        beizhu:"商品退款",
        czlx:"商品退款",
        type:1
      })
    }
      initeer()
      showModal.value = false
}
  </script>
  <style scoped>
      .sdfsdfyttytruy{
          max-height: 600px;
          overflow: auto;
      }
  
  </style>
  